package com.blogsoho.taurus.dao.mapper;

import com.blogsoho.taurus.dao.builder.CustomerSqlBuilder;
import com.blogsoho.taurus.vo.CustomerVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

/**
 * Created by 16978 on 2017/6/11.
 */
@Mapper
public interface CustomerMapper {

    @InsertProvider(type = CustomerSqlBuilder.class, method = "addCustomer")
    public int addCustomer(CustomerVO customer);

    @SelectProvider(type = CustomerSqlBuilder.class, method = "getAllCustomer")
    @Results(id = "customer", value = {
            @Result(property = "name", column = "name"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "company", column = "company"),
            @Result(property = "url", column = "url"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "alertDate", column = "alert_date", jdbcType = JdbcType.TIMESTAMP, javaType = Date.class),
            @Result(property = "enableAlert", column = "enable_alert"),
            @Result(property = "id", column = "id")
    })
    public List<CustomerVO> getAllCustomer(@Param("start") int start, @Param("length") int length);

    @SelectProvider(type = CustomerSqlBuilder.class, method = "getCountCustomer")
    public int getCountCustomer();

    @SelectProvider(type = CustomerSqlBuilder.class, method = "getCustomerById")
    @ResultMap("customer")
    public CustomerVO getCustomerById(@Param("id") int id);

    @UpdateProvider(type = CustomerSqlBuilder.class, method = "updateCustomer")
    public int updateCustomer(CustomerVO customer);

    @SelectProvider(type = CustomerSqlBuilder.class,method = "getCustomerByAlertTime")
    @ResultMap("customer")
    public List<CustomerVO> getCustomerByAlertTime(@Param("day")Integer day);
}
